package com.lmx.tour_management_system.controller;


import com.lmx.tour_management_system.mapper.*;
import com.lmx.tour_management_system.pojo.*;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
public class AdminRouterController {

    @Resource
    TouristMapper touristMapper;

    @Resource
    AttractionsMapper attractionsMapper;

    @Resource
    AccountMapper accountMapper;

    @Resource
    CommentsMapper commentsMapper;

    @Resource
    AccountTouristMapper accountTouristMapper;

    //跳转到首页
    @RequestMapping("/admin/main")
    public String toMain(){
        return "admin/main";
    }

    //跳转到游客添加页
    @RequestMapping("/admin/toTouristAdd")
    public String toTouristAdd(){
        return "admin/tourist_add";
    }

    //跳转到游客查询页
    @RequestMapping("/admin/toTouristQuery")
    public String toTouristQuery(){
        return "admin/tourist_query";
    }

    //跳转到游客列表页
    @RequestMapping("/admin/toTouristList")
    public String toTouristList(Model model){
        List<Tourist> tourists = touristMapper.selectList(null);
        model.addAttribute("tourists",tourists);
        return "admin/tourist_list";
    }


    //跳转到景点添加页
    @RequestMapping("/admin/toAttractionsAdd")
    public String toAttractionsAdd(){
        return "admin/attractions_add";
    }

    //跳转到景点查询页
    @RequestMapping("/admin/toAttractionsQuery")
    public String toAttractionsQuery(){
        return "admin/attractions_query";
    }

    //跳转到景点列表页
    @RequestMapping("/admin/toAttractionsList")
    public String toAttractionsList(Model model){
        List<Attraction> attractions = attractionsMapper.selectList(null);
        model.addAttribute("attractions",attractions);
        return "admin/attractions_list";
    }  
    
    //跳转到用户添加页
    @RequestMapping("/admin/toAccountAdd")
    public String toAccountAdd(){
        return "admin/account_add";
    }

    //跳转到用户查询页
    @RequestMapping("/admin/toAccountQuery")
    public String toAccountQuery(Model model){
        return "null";
    }

    //跳转到用户列表页
    @RequestMapping("/admin/toAccountList")
    public String toAccountList(Model model){
        List<AccountTourist> accounts = accountTouristMapper.selectList(null);
        model.addAttribute("accounts",accounts);
        return "admin/account_list";
    }

    /**
     * 评论管理
     * @param model
     * @return
     */
    @RequestMapping("/toCommentsList")
    public String toCommentsList(Model model){
        List<Comments> comments = commentsMapper.selectList(null);
        model.addAttribute("comments",comments);
        return "admin/comments_list";
    }


    /**
     * 评论删除
     * @param model
     * @return
     */
    @RequestMapping("/toCommentsDelete")
    public String toCommentsDelete(Model model){
        List<Comments> comments = commentsMapper.selectList(null);
        model.addAttribute("comments",comments);
        return "admin/comments_delete";
    }




    @RequestMapping("/admin/toUpdatePassword")
    public String toUpdatePassword(){
        return "admin/account_updatePassword";
    }




    //注销操作
    @RequestMapping("/admin/logout")
    public String logout(HttpSession session){
        session.removeAttribute("loginUser");
        return "redirect:/toIndex";
    }

}
